package main

import (
	"fmt"
	"github.com/the404/letcode/common"
)

// todo 待解决，有两个错误节点，恢复二叉树
func main() {
	var arr []*int

	t := getbaseTree()
	InOrderTraver(t, &arr)
	printArr(arr)
}
func getbaseTree() *common.TreeNode {


	t3 := &common.TreeNode{2, nil, nil}
	t2 := &common.TreeNode{3, nil, t3}
	t1 := &common.TreeNode{1, t2, nil}

	//t3 := &common.TreeNode{3, nil, nil}
	//t2 := &common.TreeNode{1, nil, nil}
	//t1 := &common.TreeNode{2, t2, t3}

	//t2 := &common.TreeNode{1, nil, nil}
	//t1 := &common.TreeNode{1, t2, nil}
	return t1
}
func printArr(arr []*int) {
	for _, v := range arr {
		if v != nil {
			fmt.Printf("%v  ", *v)
		} else {
			fmt.Printf("%v  ", v)
		}
	}
}

func recoverTree(root *common.TreeNode) {

}

func InOrderTraver(t *common.TreeNode, arr *[]*int) {
	if t == nil {
		return
	}

	if t.Left != nil {
		InOrderTraver(t.Left, arr)
	} else {
		*arr = append(*arr, nil)
	}

	*arr = append(*arr, &t.Val)

	if t.Right != nil {
		InOrderTraver(t.Right, arr)
	} else {
		*arr = append(*arr, nil)
	}
}
